﻿using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace YJKCopyModel.Basic
{
	public class WindowsApi
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		[DllImport("User32.dll")]
		private static extern int SendMessage(int Handle, int wMsg, int wParam, int lParam);

		[DllImport("user32.dll")]
		public static extern IntPtr GetActiveWindow();

		[DllImport("user32.dll")]
		public static extern IntPtr SetActiveWindow(IntPtr hwnd);

		[DllImport("user32.dll")]
		public static extern bool SetForegroundWindow(IntPtr hWnd);

		[DllImport("User32.dll")]
		public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);

		[DllImport("user32.dll")]
		public static extern bool SetCursorPos(int X, int Y);

		[DllImport("user32.dll")]
		public static extern int ShowScrollBar(int hwnd, int wBar, int bShow);

		public static void SendEsc()
		{
			byte bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			WindowsApi.keybd_event(bVk, 0, dwFlags, 0);
			WindowsApi.keybd_event(bVk, 0, dwFlags2, 0);
		}

		public static void SetListViewSpacing(ListView lst, int x, int y)
		{
			WindowsApi.SendMessage(lst.Handle.ToInt32(), 4149, 0, x * 65536 + y);
		}

		public static void SetListViewScrollBar(ListView lst, int x, int y)
		{
			WindowsApi.ShowScrollBar((int)lst.Handle, x, y);
		}

		private const int LVM_FIRST = 4096;

		private const int LVM_SETICONSPACING = 4149;

		private const int SB_HORZ = 0;

		private const int SB_VERT = 1;

		private const int SB_CTL = 2;

		private const int SB_BOTH = 3;
	}
}
